clear all;

data.income_gini_data=[0.478511948789390	0.470386191574900	0.513187946459395	0.536462695460128	0.493752475059723];
data.top10=[0.364169212322523	0.353238721670772	0.401748266399825	0.424131593755188	0.381703049870163];
data.bottom50=[0.186443728639779	0.188890122017759	0.171447185809140	0.159473075067075	0.180559369053430];

model=load('model\result_baseline.mat');
credit=load('model\result_credit.mat');
deposit=load('model\result_deposit.mat');

xdata=[86,88,90,92,96];
xmodel=86:1:96;

fig=figure('Position',[20,40,1400,320],'Color',[1,1,1]);
% ah1 = axes('Parent',fig,'Units','normalized','Position',[0.1300 0.1510 0.1727 0.7693]);
subplot(1,3,1)
plot(1e10,1e10,'-b','linewidth',2)
hold on
plot(1e10,1e10,'-.r','linewidth',2)
plot(1e10,1e10,':g','linewidth',2)
plot(1e10,1e10,'--k','linewidth',2)

% axis square
yyaxis left
plot(xmodel,model.income_gini(1:11),'-b','linewidth',2)
yyaxis right
hold on
plot(xdata,data.income_gini_data,'--k','linewidth',2)
hold on
yyaxis left
plot(xmodel,credit.income_gini(1:11),'-.r','linewidth',2)
hold on
plot(xmodel,deposit.income_gini(1:11),':g','linewidth',2)
legend('model','credit channel','deposit channel','data',...
    'interpreter','latex','location',[0.1803 0.814 0 0],'Numcolumns',1)
xlabel('year', 'FontSize',12,'Interpreter','Latex');
ylabel('income Gini', 'FontSize',12,'Interpreter','Latex');
xlim([86 96]);
set(gca,'FontSize',11);
title( 'A. Income Gini', 'FontSize',13,'Interpreter','Latex');
ax = gca;
ax.YAxis(1).Color = 'b';
ax.YAxis(2).Color = 'k';

a=mean(model.income_gini(1:11));
b=mean(data.income_gini_data)+0.002; % purely for visual effect

yyaxis left
yl1=[0.36,0.48];
ytic1=0.36:0.03:0.48;
ylim(yl1);
yticks(ytic1);

yyaxis right
yl2=yl1+b-a;
ylim(yl2)
ntick=length(ytic1);
ytic2=ytic1+b-a;
ytic2_label=cell(ntick,1);
for i=1:ntick
    ytic2_label{i}=strcat(num2str(ytic1(i)),strrep(num2str(floorS(b-a,2),'%+.2f'),'0.','.'));
end
yticks(ytic2);
set(gca,'ytick',ytic2,'yticklabel',ytic2_label)


% ah2 = axes('Parent',fig,'Units','normalized','Position',[0.4108 0.1510 0.1727 0.7693]);
subplot(1,3,2)
% axis square
yyaxis left
plot(xmodel,model.prc10,'-b','linewidth',2)
yyaxis right
hold on
plot(xdata,data.top10,'--k','linewidth',2)
hold on
yyaxis left
plot(xmodel,credit.prc10,'-.r','linewidth',2)
hold on
plot(xmodel,deposit.prc10,':g','linewidth',2)
xlabel('year', 'FontSize',12,'Interpreter','Latex');
ylabel('share of aggregate income', 'FontSize',12,'Interpreter','Latex');
xlim([86 96]);
set(gca,'FontSize',11);
title( 'B. Top 10\% share of aggregate income', 'FontSize',13,'Interpreter','Latex');
ax = gca;
ax.YAxis(1).Color = 'b';
ax.YAxis(2).Color = 'k';

a=mean(model.prc10);
b=mean(data.top10)+0.002; % purely for visual effect

yyaxis left
yl1=[0.35,0.45];
ytic1=0.35:0.02:0.45;
ylim(yl1);
yticks(ytic1);
yyaxis right
yl2=yl1+b-a;
ylim(yl2)
ntick=length(ytic1);
ytic2=ytic1+b-a;
ytic2_label=cell(ntick,1);
for i=1:ntick
    ytic2_label{i}=strcat(num2str(ytic1(i)),strrep(num2str(floorS(b-a,2),'%+.2f'),'0.','.'));
end
yticks(ytic2);
set(gca,'ytick',ytic2,'yticklabel',ytic2_label)

% ah3 = axes('Parent',fig,'Units','normalized','Position',[0.6916 0.1510 0.1727 0.7693]);
subplot(1,3,3)
% axis square
yyaxis left
plot(xmodel,1-model.prc50,'-b','linewidth',2)
yyaxis right
hold on
plot(xdata,data.bottom50,'--k','linewidth',2)
hold on
yyaxis left
plot(xmodel,1-credit.prc50,'-.r','linewidth',2)
hold on
plot(xmodel,1-deposit.prc50,':g','linewidth',2)
xlabel('year', 'FontSize',12,'Interpreter','Latex');
ylabel('share of aggregate income', 'FontSize',12,'Interpreter','Latex');
xlim([86 96]);
set(gca,'FontSize',11);
title( 'C. Bottom 50\% share of aggregate income', 'FontSize',13,'Interpreter','Latex');
ax = gca;
ax.YAxis(1).Color = 'b';
ax.YAxis(2).Color = 'k';

a=mean(1-model.prc50);
b=mean(data.bottom50)-0.002; % purely for visual effect

yyaxis left
yl1=[0.237,0.282];
ytic1=0.24:0.01:0.28;
ylim(yl1);
yticks(ytic1);
yyaxis right
yl2=yl1+b-a;
ylim(yl2)
ntick=length(ytic1);
ytic2=ytic1+b-a;
ytic2_label=cell(ntick,1);
for i=1:ntick
    ytic2_label{i}=strcat(num2str(ytic1(i)),strrep(num2str(floorS(b-a,2),'%+.2f'),'0.','.'));
end
yticks(ytic2);
set(gca,'ytick',ytic2,'yticklabel',ytic2_label)
